//
// 通用定时器框架
// Created by kenny on 25-11-6.
//

#ifndef COMM_TIMER_H
#define COMM_TIMER_H
#include "comm_timer.h"
#include "../platform/platform_timer.h"
#include <stdbool.h>
// 定时器的配置
typedef struct {
    bool enabled;               // 是否启用定时任务
    unsigned int interval_sec;  // 间隔（秒）
    void (*user_func)(void* user_data);  // 业务函数
    void* user_data;            // 用户数据，传递给上报函数
} timer_config_t;

typedef enum {
    TIMER_STOPPED = 0,
    TIMER_RUNNING,
    TIMER_DESTROYED
} timer_state_t;

typedef struct {
    timer_config_t config;
    timer_state_t state;
    platform_timer_t* platform_timer;
    void* thread_handle;
} comm_timer_t;

// 统一的接口函数
comm_timer_t* comm_timer_create(const timer_config_t* config);
bool comm_timer_start(comm_timer_t* timer);
bool comm_timer_stop(comm_timer_t* timer);
bool comm_timer_destroy(comm_timer_t* timer);
#endif //COMM_TIMER_H
